/* 
 * File:   dat_quene.h
 * Author: aple
 */

#ifndef __SW_PWM_H_H_
#define	__SW_PWM_H_H_

#include "stdint.h"

#ifdef	__cplusplus
extern "C" {
#endif


	//软件PWM输出处理
	typedef struct
	{
		//外部更新
		uint32_t period_set;
		uint32_t duty_set;
		uint8_t en;
		//内部管理
		uint32_t period_now;
		uint32_t duty_now;
		uint32_t cnt;
		uint8_t out;
	} sim_pwm_type;

	uint8_t sim_pwm_cal(sim_pwm_type * obj);

	typedef struct
	{
		//外部更新
		uint32_t period_set;
		uint8_t * duty_set_list;
		uint8_t en;
		uint8_t duty_len;

		//内部管理
		uint8_t * duty_now_list;
		uint8_t duty_index;
		uint8_t period_now;
		uint8_t duty_now;
		uint8_t cnt;

		uint8_t out;
	} sim_pwms_type;
	
	uint8_t sim_pwm_list_handle(sim_pwms_type * obj);
	
	//--数据平均分割
	void average_segmentation_u16(uint16_t dat, uint16_t amount, uint8_t *des);

	typedef struct
	{
		//外部更新
		uint8_t en_mode;  //Y //0无输出
		uint8_t out;
		uint16_t period_set;//Y
		uint8_t * duty_set_list; //Y  //elec_site_average函数生成的输出列表


		//有效时可更新设定值，也可作为PID计算周期标记，使用后由应用程序清零
		uint8_t set_update_req;

		//内部管理
		uint8_t * duty_now_list;//Y/X  en_mode=2时内部加载，1时外部加载
		uint16_t period_now;
		uint16_t cnt;
	} sim_elec_out_type;

	uint8_t sim_elec_out_list_handle(sim_elec_out_type * obj);
	void elec_site_average(uint8_t *list, uint16_t period, uint16_t val);


#ifdef	__cplusplus
}
#endif

#endif	/* __SW_PWM_H_H_ */

